﻿using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;


namespace HAVNet.Core.IO
{
    public class XMLSer
    {
        public static void serializar (string path, object o)
        {
            XmlSerializer xmlSerializer = new XmlSerializer (o.GetType());

            using (TextWriter stream = new StreamWriter (path))
            {
                xmlSerializer.Serialize (stream, o);
                stream.Close();
            }
        }

        public static object deserializar (string path, Type t)
        {
            object ret = null;
            XmlSerializer xmlSerializer = new XmlSerializer (t);

            using (FileStream fstream = new FileStream (path, FileMode.Open))
            {
                ret = xmlSerializer.Deserialize (fstream);
                fstream.Close ();
            }

            return ret;
        }
    }
}
